import Vue from 'vue'
import VueRouter from 'vue-router'
import login from '../views/login'
import home from '../views/home'
import register from '../views/register'
import ProductDetails from '../views/ProductDetails'
import ProductList from '../views/ProductList'
import spikeMerchandise from '../views/spikeMerchandise'
import spikeDetail from '../views/spikeDetail'
import orderPage from '../views/orderPage'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
  {
    path: '/',
    component: home,
    children:[
      {
        path:'/spikeMerchandise',
        name:'spikeMerchandise',
        component:spikeMerchandise,
      },
      {
        path: '/ProductList',
        name: 'ProductList',
        component: ProductList,
      },
      {
        path: '/ProductDetails',
        name: 'ProductDetails',
        component: ProductDetails,
      },
      {
        path: '/orderPage',
        name: 'orderPage',
        component: orderPage,
        meta:{requiresAuth: true},
      },
      {
        path: '/spikeDetail',
        name: 'spikeDetail',
        component: spikeDetail,
        meta:{requiresAuth: true},
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/register',
    name: 'register',
    component: () => import(/* webpackChunkName: "about" */ '../views/register.vue')
  }
  // {
    // which is lazy-loaded when the route is visited.
    //component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  mode: 'hash',
  // base: process.env.BASE_URL,
  routes
})

export default router
